package com.hefeng.unit.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hefeng.unit.domain.GyUser;
import com.hefeng.unit.mapper.GyUserMapper;
import com.hefeng.unit.service.GyUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 工业端微信用户表;(gy_user)表服务实现类
 * @author : hzh
 * @date : 2022-9-22
 */
@Service
public class GyUserServiceImpl extends ServiceImpl<GyUserMapper, GyUser> implements GyUserService {
    @Autowired
    private GyUserMapper gyUserMapper;


     @Override
     public GyUser getWxuserById(String openid) {
         LambdaQueryWrapper<GyUser> queryWrapper = new LambdaQueryWrapper<>();
         queryWrapper.eq(GyUser::getWxOpenId,openid);
         return gyUserMapper.selectOne(queryWrapper);
     }

    @Override
    public Map saveResident(GyUser gyUser) {
        Map<String,Object>map=new HashMap<>();
        try {
            gyUser.setWxState(1);
            gyUser.setWxUserType(1);
            gyUser.setCreatedTime(new Date());
            int make=gyUserMapper.insert(gyUser);
            map.put("userId",gyUser.getUserId());
            //添加成功后推送到燃气接口
            if(make>0){

            }
        }catch (Exception e){
            map.put("data","");
        }
        return map;

    }

    @Override
    public int update(GyUser gyUser) {
        return gyUserMapper.updateById(gyUser);
    }
}